package com.jyw.business.obstacles.wechat.controller;

import com.jyw.business.de.domain.dto.web.ObsDemandAddDto;
import com.jyw.business.de.domain.dto.web.ObsTaskAddDto;
import com.jyw.business.obstacles.domain.dto.web.*;
import com.jyw.business.obstacles.domain.dto.wechat.EvaluateOrderDto;
import com.jyw.business.obstacles.domain.dto.wechat.WorkOrderQueryDto;
import com.jyw.business.obstacles.domain.dto.wechat.WxOrderTimeOutDto;
import com.jyw.business.obstacles.domain.vo.wechat.WorkOrderQueryVO;
import com.jyw.business.obstacles.expand.service.IObsDemandService;
import com.jyw.business.obstacles.service.IObsOrderFaultService;
import com.jyw.business.obstacles.service.IObsOrderMakeService;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.system.utils.ConversionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 我的工单
 */
@RestController
@RequestMapping("/wechat/workOrder")
@Api(tags = "我的工单")
public class ObsWorkOrderController extends BaseController {

    @Resource
    private IObsOrderFaultService orderFaultService;

    @Resource
    private IObsOrderMakeService iObsOrderMakeService;

    @Resource
    private IObsDemandService obsDemandService;

    @ApiOperation("工单列表")
    @PostMapping("/listWeChatOrder")
    public TableDataInfo<WorkOrderQueryVO> listWeChatOrder(@RequestBody WorkOrderQueryDto pageDto) {
        List<WorkOrderQueryVO> list = orderFaultService.listWeChatOrder(pageDto);
        list = ConversionUtil.conversionList(list,WorkOrderQueryVO.class);
        return getDataTable(list);
    }

    @PutMapping("/restart")
    @ApiOperation("重启")
    public CommonResult restart(@Validated @RequestBody BaseOrderDto orderDto) {
        iObsOrderMakeService.restart(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/open")
    @ApiOperation("开启")
    public CommonResult open(@Validated @RequestBody BaseOrderDto orderDto) {
        iObsOrderMakeService.open(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/revokeReview")
    @ApiOperation("撤销审核")
    public CommonResult revokeReview(@Validated @RequestBody BaseOrderDto orderDto) {
        iObsOrderMakeService.revokeReview(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/receive")
    @ApiOperation("接单")
    public CommonResult receive(@Validated @RequestBody ReceiveOrderDto orderDto) {
        iObsOrderMakeService.receive(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/termination")
    @ApiOperation("终止")
    public CommonResult termination(@Validated @RequestBody OrderTerminationDto orderDto) {
        iObsOrderMakeService.termination(orderDto);
        return CommonResult.success();
    }

    @PutMapping("suspend")
    @ApiOperation("暂停")
    public CommonResult suspend(@RequestBody OrderSuspendDto orderDto){
        iObsOrderMakeService.suspend(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/reback")
    @ApiOperation("退单")
    public CommonResult reback(@Validated @RequestBody OrderRebackDto orderDto) {
        iObsOrderMakeService.reback(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/complete")
    @ApiOperation("完成工单")
    public CommonResult complete(@Validated @RequestBody CompleteOrderDto orderDto) {
        iObsOrderMakeService.complete(orderDto);
        return CommonResult.success();
    }

    @PostMapping("/evaluate")
    @ApiOperation("评价")
    public CommonResult evaluate(@Validated @RequestBody EvaluateOrderDto dto) {
        iObsOrderMakeService.evaluate(dto);
        return CommonResult.success();
    }

    @PutMapping("/make")
    @ApiOperation("处理工单")
    public CommonResult make(@Validated @RequestBody MakeOrderDto orderDto) {
        iObsOrderMakeService.make(orderDto);
        return CommonResult.success();
    }


    @PutMapping("/redirect")
    @ApiOperation("转单")
    public CommonResult redirect(@Validated @RequestBody OrderRedirectDto orderDto) {
        iObsOrderMakeService.redirect(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/assist")
    @ApiOperation("协作工单")
    public CommonResult assist(@Validated @RequestBody AssistOrderDto orderDto) {
        iObsOrderMakeService.assist(orderDto);
        return CommonResult.success();
    }

    @PutMapping("/upgrade")
    @ApiOperation("升级工单")
    public CommonResult upgrade(@Validated @RequestBody OrderUpgradeDto orderDto) {
        iObsOrderMakeService.upgrade(orderDto);
        return CommonResult.success();
    }

    /**
     * 工单转需求
     * @param orderDto
     * @return
     */
    @PutMapping("transfer/demand")
    @ApiOperation("工单转需求")
    public CommonResult transferDemand(@RequestBody ObsDemandAddDto orderDto){
        obsDemandService.transferDemand(orderDto);
        return CommonResult.success();
    }


    /**
     * 工单转任务
     * @param orderDto
     * @return
     */
    @PutMapping("transfer/task")
    @ApiOperation("工单转任务")
    public CommonResult transferTask(@RequestBody ObsTaskAddDto orderDto){
        obsDemandService.transferTask(orderDto);
        return CommonResult.success();
    }

    /**
     * 工单催单
     *
     * @param orderReminderDto
     * @return
     */
    @PutMapping("/reminder")
    @ApiOperation("工单催单")
    public CommonResult reminder(@RequestBody @Valid OrderReminderDto orderReminderDto) {
        iObsOrderMakeService.reminder(orderReminderDto);
        return CommonResult.success();
    }

    /**
     * 工单超时备注
     *
     * @param dto
     * @return
     */
    @PutMapping("/time/out/remark")
    @ApiOperation("工单超时备注")
    public CommonResult timeOutRemark(@RequestBody @Valid WxOrderTimeOutDto dto) {
        iObsOrderMakeService.timeOutRemark(dto);
        return CommonResult.success();
    }
}
